const action_type = {
    ADD: 'ADD',
    DECREASE: 'DECREASE',
}

export function counter (state={num:0},action) {
    switch (action.type) {
        case action_type.ADD :
            return {
                ...state,
                num: state.num + 1,
            };
        break;
        case action_type.DECREASE :
            return {
                ...state,
                num: state.num - 1,
            }
        default :
            return {
                ...state,
                num: 10
            };
        break;
    }
}

export function add () {
    return {
        type: action_type.ADD
    }
}

export function decrease () {
    return {
        type: action_type.DECREASE
    }
}

export function addAsync () {
    return dispatch => {
        setTimeout(()=>{
            dispatch(add());
        },1000);
    }
}